package com.efast.dmom.mgmt.service.master.impl;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.dao.master.TmBasDefectCodeMapper;
import com.efast.dmom.mgmt.entity.master.TmBasDefectCode;
import com.efast.dmom.mgmt.entity.master.TmBasDefectGroup;
import com.efast.dmom.mgmt.service.master.TmBasDefectCodeService;
import com.efast.dmom.mgmt.service.master.TmBasDefectGroupService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 质量模块的错误代码定义 服务实现类
 * </p>
 *
 * @author Xu Cong
 * @since 2018-09-20
 */
@Service
public class TmBasDefectCodeServiceImpl extends ServiceImpl<TmBasDefectCodeMapper, TmBasDefectCode> implements TmBasDefectCodeService {

	@Autowired
	private TmBasDefectGroupService tmBasDefectGroupService;
	
	@Override
	public void save(TmBasDefectCode tmBasDefectCode) {
		EntityWrapper<TmBasDefectCode> wrapper = new EntityWrapper<>();
		TmBasDefectGroup tmBasDefectGroup = tmBasDefectGroupService.selectById(tmBasDefectCode.getTmBasDefectGroupId());
		if(tmBasDefectGroup!=null) {
			tmBasDefectCode.setDefectGroupName(tmBasDefectGroup.getDefectGroupName());
		}
		tmBasDefectCode.setCreateTime(new Date());
		tmBasDefectCode.setCreateUser(SpringWebUtils.getRequestUser());
		tmBasDefectCode.setCompanyCode(SpringWebUtils.getRequestCompany());
		this.insert(tmBasDefectCode);
	}

}
